(function(){
    $.extend({
        decorate:function(dom){
            var files = Array.prototype.slice.call(dom.files);
            var promise = $.Deferred();
            var pics = [];
            var wait = function(file){
                var dtd = $.Deferred();
                lrz(file).then(function (rst) {
                    dtd.resolve(rst.base64);
                })
                .catch(function (err) {
                    dtd.reject(err);
                })
                return dtd;
            }
            var compress = function(){
                var file = files.shift();
                if(file){
                    $.when(wait(file)).done(function(base64){
                        pics.push(base64);
                        compress();
                    }).fail(function(err){
                        promise.reject(err);
                    })
                }else{
                    promise.resolve(pics);
                    return;
                }
            }
            compress();
            return $.when(promise);
        }
    })
})();